import { createRouter, createWebHashHistory } from "vue-router";
// 导入路由路径
import { routes } from './routes'
// 创建路由
const router = createRouter({
    // createWebHashHistory路径有#号，createWebHistory路径不包含#。使用web方式部署到服务器刷新会报404错误
    history: createWebHashHistory(),
    routes
});
// 路由守卫
router.beforeEach((to, from, next) => {
    const userInfo = localStorage.getItem('userInfo');
    if (!userInfo && to.path !== '/login') {
        next('/login');
    } else {
        next()
    }
});
export default router